from django.db import models

category_arr1 = (
        (1, '蔬菜'),
        (2, '水果'),
        (3, '肉禽蛋'),
        (4, '水产'),
        (5, '粮油'),
        (6, '豆制品'),
        (7, '调料')
)

category_arr2 = (
        (1, '水菜'),
        (2, '特菜'),
        (3, '进口果'),
        (4, '干果'),
        (5, '猪肉类'),
        (6, '牛肉类'),
        (7, '羊肉类'),
        (8, '禽蛋类'),
        (9, '淡水鱼'),
        (10, '海水鱼'),
        (11, '虾蟹类'),
        (12, '贝壳类'),
        (13, '其他类'),
        (14, '米面类'),
        (15, '杂粮类'),
        (16, '食用油'),
)

# 一级分类
class Category1(models.Model):
    def __str__(self):
        return str(self.id)

    category_name = models.CharField(max_length=30, verbose_name='一级分类名称')

    # 管理后台显示标题
    class Meta:
        db_table = 'newmarket_category1'
        verbose_name_plural = verbose_name = '一级分类表'

        # 管理后台按照id升序显示
        ordering = ['id']


# 二级分类
class Category2(models.Model):
    def __str__(self):
        return str(self.id)

    fid = models.SmallIntegerField(choices=category_arr1, verbose_name='一级分类名称')
    category_name = models.CharField(max_length=30, verbose_name='二级分类名称')

    # 管理后台显示标题
    class Meta:
        db_table = 'newmarket_category2'
        verbose_name_plural = verbose_name = '二级分类表'

        # 管理后台按照id升序显示
        ordering = ['id']


# 价格行情表
class Detail(models.Model):
    def __str__(self):
        return str(self.id)

    cid1 = models.SmallIntegerField(choices=category_arr1, verbose_name='一级分类名称', db_index=True)
    cid2 = models.SmallIntegerField(choices=category_arr2, verbose_name='二级分类名称', db_index=True)
    market_name = models.CharField(max_length=30, verbose_name='菜市名称')
    product_name = models.CharField(max_length=30, verbose_name='品目名称')
    min_price = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='最低价')
    avg_price = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='正常价')
    max_price = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='最高价')
    standards = models.CharField(max_length=30, verbose_name='规格')
    place = models.CharField(max_length=30, verbose_name='产地')
    unit = models.CharField(max_length=10, verbose_name='单位')
    pub_date = models.DateField(verbose_name='发布时间', db_index=True)

    # 管理后台显示标题
    class Meta:
        db_table = 'newmarket_detail'
        verbose_name_plural = verbose_name = '行情数据表'

        # 管理后台按照id升序显示
        ordering = ['id']